﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Web.Admin.Presenters;
using SonCa.SocialNetwork.Web.Admin.IPresenters;
using Core.DataAccess;
using Core.Common;

namespace SonCa.SocialNetwork.Web.Admin
{
    public partial class MemberPage : System.Web.UI.Page, IMemberPresenter
    {
        private MemberPresenter _presenter;

        protected void Page_Load(object sender, EventArgs e)
        {            
            _presenter = new MemberPresenter();
            _presenter.Init(this);
        }                

        protected void rptMember_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptLevel = (Repeater)e.Item.FindControl("rptLevelMember");
                rptLevel.DataSource = _presenter.GetAllLevels();
                rptLevel.DataBind();
            }
        }

        public void DisplayListMember(List<Account> lstAccount)
        {
            if (lstAccount != null && lstAccount.Count > 0)
            {
                List<MemberAdmin> lstMember = new List<MemberAdmin>();
                lstAccount.ForEach(item => lstMember.Add(new MemberAdmin
                {
                    AccountID = item.AccountID,
                    Username = item.Username,
                    FullName = item.LastName + " " + item.MidName + " " + item.FirstName,
                    Email = item.Email,
                    LevelName = _presenter.GetLevelNameByLevelID(Convert.ToInt32(item.LevelID)),
                    Score = Convert.ToInt32(item.Score),
                    IsLock = Convert.ToBoolean(item.IsLock)
                }));

                rptMember.DataSource = lstMember;
                rptMember.DataBind();
            }
            else
            {
                lblMessage.Text = "Hiện chưa có thành viên.";
                lblMessage.Visible = true;
            }
        }
    }
}